package flc.ast.activity;

import androidx.annotation.NonNull;
import androidx.appcompat.app.AppCompatActivity;
import androidx.recyclerview.widget.GridLayoutManager;

import android.os.Bundle;
import android.view.View;

import com.chad.library.adapter.base.BaseQuickAdapter;
import com.stark.guesstv.lib.module.GtDataProvider;
import com.stark.guesstv.lib.module.bean.TvActorBean;
import com.stark.guesstv1.lib.model.TvPlayBean;
import com.stark.guesstv1.lib.model.TvPlayDataProvider;

import java.util.ArrayList;
import java.util.List;

import flc.ast.BaseAc;
import flc.ast.R;
import flc.ast.adapter.SelLevelAdapter;
import flc.ast.databinding.ActivitySelTvLevelBinding;
import flc.ast.utils.Content;
import stark.common.basic.utils.SPUtil;

public class SelTvLevelActivity extends BaseAc<ActivitySelTvLevelBinding> {

    private int oldLevel;
    private String levelName;
    private List<Integer> listShow = new ArrayList<>();//展示的数据
    private SelLevelAdapter levelAdapter;

    @Override
    protected int onCreate() {
        return R.layout.activity_sel_tv_level;
    }

    @Override
    protected void initView() {
        mDataBinding.ivSelTvLevelBack.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                onBackPressed();
            }
        });
        mDataBinding.rvLevelList.setLayoutManager(new GridLayoutManager(mContext, 4));
        levelAdapter = new SelLevelAdapter();
        mDataBinding.rvLevelList.setAdapter(levelAdapter);
        levelAdapter.setOnItemClickListener(this);
    }

    @Override
    protected void onItemClickCallback(@NonNull BaseQuickAdapter<?, ?> adapter, @NonNull View view, int position) {
        if (levelAdapter.getItem(position) > (oldLevel - 1)) return;
        Game2Activity.level=position;
        startActivity(Game2Activity.class);
    }

    @Override
    protected void initData() {

    }

    @Override
    protected void onResume() {
        super.onResume();
        getData();
    }

    private void getData(){
        List<TvActorBean> tvData = GtDataProvider.getTvData();
        oldLevel = SPUtil.getInt(mContext, Content.GAME_NAME2, 1);//获取对应难度的关卡进度
        levelName = Content.GAME_NAME2;
        listShow.clear();
        for (int i = 0; i <tvData.size() ; i++) {
            listShow.add(i);
        }
        levelAdapter.setType(1);
        levelAdapter.setList(listShow);
        //根据关卡名称获取过关数量
        levelAdapter.setLevelName(levelName);
        levelAdapter.notifyDataSetChanged();
    }

}